<?php
namespace caches;

use components\O;

class BaseCache
{
	public static function gen(){
		return call_user_func_array('sprintf',func_get_args()) ;
	}

	public static function __callStatic($name, $params){
        $conn = O::$app->redis;
        return call_user_func_array([$conn, $name], $params);
    }

    public static function setex($key,$expire,$val){
    	if(is_array($val)){
    		$val = json_encode($val);
    	}
    	return O::$app->redis->setex($key,$expire,$val);
    }
    public static function get($key){
    	$raw = O::$app->redis->get($key);
    	!empty($raw) && ($val = json_decode($raw,true));
    	return is_array($val) ? $val : $raw ;
    }
}